let devList = [
  {
    "date": "2024-09-13 15:34:32",
    "meter_status": null,
    "meterbalance": null,
    "code": "891024090207",
    "account_balance": 0,
    "address_desc": "洺月测试小区891024090207",
    "user_name": "891024090207",
    "interactive": "2024-09-13 00:00:00",
    "flowrate": null,
    "matter": "",
    "devicetype": "PAYMONTH",
    "working_condition": null,
    "user_type": "RESIDENT",
    "equip_id": "2c9ff3b691d49a740191ea29a8ad3a3c",
    "balance": 0,
    "temperature": null,
    "model": null,
    "tel": "891024090207",
    "id": "2c9ff3b691d49a740191ea4e16a33b56",
    "power": null,
    "current_num": 0,
    "cost": 0,
    "valve_status": null,
    "net_type": "NBIOT",
    "userno": "0000064661",
    "area_code": "0000000676",
    "gift_balance": 0,
    "equip_name": "物联网无阀水表",
    "area_full_desc": "洺月测试小区",
    "voltage": null,
    "addressid": "2c9ff3b691d49a740191ea4e349f3b61",
    "signals": null,
    "synchronization": true,
    "devicename": "睿联智能NB蓝牙后付费水表",
    "area_desc": "洺月测试小区",
    "net_worked": true,
    "status": "USING"
  },
  {
    "date": "2024-09-15 08:22:45",
    "meter_status": null,
    "meterbalance": null,
    "code": "891024090208",
    "account_balance": 15,
    "address_desc": "华清水务小区A栋3单元",
    "user_name": "李明",
    "interactive": "2024-09-15 00:00:00",
    "flowrate": null,
    "matter": "",
    "devicetype": "PAYMONTH",
    "working_condition": null,
    "user_type": "RESIDENT",
    "equip_id": "2c9ff3b691d49a740191ea29a8ad3a3d",
    "balance": 15,
    "temperature": null,
    "model": null,
    "tel": "13812345678",
    "id": "2c9ff3b691d49a740191ea4e16a33b57",
    "power": null,
    "current_num": 12.5,
    "cost": 25,
    "valve_status": null,
    "net_type": "NBIOT",
    "userno": "0000064662",
    "area_code": "0000000677",
    "gift_balance": 0,
    "equip_name": "物联网无阀水表",
    "area_full_desc": "华清水务小区",
    "voltage": null,
    "addressid": "2c9ff3b691d49a740191ea4e349f3b62",
    "signals": null,
    "synchronization": true,
    "devicename": "睿联智能NB蓝牙后付费水表",
    "area_desc": "华清水务小区",
    "net_worked": true,
    "status": "USING"
  },
  {
    "date": "2024-09-12 11:45:18",
    "meter_status": null,
    "meterbalance": null,
    "code": "891024090209",
    "account_balance": 5,
    "address_desc": "蓝天水务公司办公楼",
    "user_name": "张三",
    "interactive": "2024-09-12 00:00:00",
    "flowrate": null,
    "matter": "水表异常",
    "devicetype": "PAYMONTH",
    "working_condition": null,
    "user_type": "BUSINESS",
    "equip_id": "2c9ff3b691d49a740191ea29a8ad3a3e",
    "balance": 5,
    "temperature": null,
    "model": null,
    "tel": "13987654321",
    "id": "2c9ff3b691d49a740191ea4e16a33b58",
    "power": null,
    "current_num": 45.8,
    "cost": 120,
    "valve_status": null,
    "net_type": "NBIOT",
    "userno": "0000064663",
    "area_code": "0000000678",
    "gift_balance": 0,
    "equip_name": "物联网无阀水表",
    "area_full_desc": "蓝天水务公司",
    "voltage": null,
    "addressid": "2c9ff3b691d49a740191ea4e349f3b63",
    "signals": null,
    "synchronization": false,
    "devicename": "睿联智能NB蓝牙后付费水表",
    "area_desc": "蓝天水务公司",
    "net_worked": false,
    "status": "ALARM"
  },
  {
    "date": "2024-09-16 16:30:22",
    "meter_status": null,
    "meterbalance": null,
    "code": "891024090210",
    "account_balance": 30,
    "address_desc": "清源水表厂测试区",
    "user_name": "王五",
    "interactive": "2024-09-16 00:00:00",
    "flowrate": null,
    "matter": "",
    "devicetype": "PAYMONTH",
    "working_condition": null,
    "user_type": "INDUSTRY",
    "equip_id": "2c9ff3b691d49a740191ea29a8ad3a3f",
    "balance": 30,
    "temperature": null,
    "model": null,
    "tel": "15012345678",
    "id": "2c9ff3b691d49a740191ea4e16a33b59",
    "power": null,
    "current_num": 78.2,
    "cost": 156,
    "valve_status": null,
    "net_type": "NBIOT",
    "userno": "0000064664",
    "area_code": "0000000679",
    "gift_balance": 5,
    "equip_name": "物联网无阀水表",
    "area_full_desc": "清源水表厂",
    "voltage": null,
    "addressid": "2c9ff3b691d49a740191ea4e349f3b64",
    "signals": null,
    "synchronization": true,
    "devicename": "睿联智能NB蓝牙后付费水表",
    "area_desc": "清源水表厂",
    "net_worked": true,
    "status": "USING"
  },
  {
    "date": "2024-09-10 09:15:40",
    "meter_status": null,
    "meterbalance": null,
    "code": "891024090211",
    "account_balance": 0,
    "address_desc": "润泽水务集团总部",
    "user_name": "赵六",
    "interactive": "2024-09-10 00:00:00",
    "flowrate": null,
    "matter": "欠费停水",
    "devicetype": "PAYMONTH",
    "working_condition": null,
    "user_type": "BUSINESS",
    "equip_id": "2c9ff3b691d49a740191ea29a8ad3a40",
    "balance": 0,
    "temperature": null,
    "model": null,
    "tel": "18987654321",
    "id": "2c9ff3b691d49a740191ea4e16a33b60",
    "power": null,
    "current_num": 102.6,
    "cost": 205,
    "valve_status": null,
    "net_type": "NBIOT",
    "userno": "0000064665",
    "area_code": "0000000680",
    "gift_balance": 0,
    "equip_name": "物联网无阀水表",
    "area_full_desc": "润泽水务集团",
    "voltage": null,
    "addressid": "2c9ff3b691d49a740191ea4e349f3b65",
    "signals": null,
    "synchronization": false,
    "devicename": "睿联智能NB蓝牙后付费水表",
    "area_desc": "润泽水务集团",
    "net_worked": false,
    "status": "STOPPED"
  }
]

let sqlStatements = [];

// 开始一个事务以提高性能
sqlStatements.push('BEGIN TRANSACTION;');

devList.forEach(device => {
  // 准备SQL语句 - 使用INSERT OR REPLACE语法实现插入或更新
  const sql = `INSERT OR REPLACE INTO water_devices 
    (deviceCode, updateTime, deviceTotalData, deviceName, deviceAddress) 
    VALUES 
    ('${device.code}', 
     '${device.date}', 
     ${device.current_num || 0}, 
     '${(device.user_name || '').replace(/'/g, "''")}', 
     '${(device.address_desc || '').replace(/'/g, "''")}');`;
  
  sqlStatements.push(sql);
});

// 提交事务
sqlStatements.push('COMMIT;');

// 输出所有SQL语句
console.log(sqlStatements.join('\n'));

